var https = require('https');
var qs = require('querystring');
var fs = require('fs')



module.exports =function(client_id,client_secret,type){
    const param = qs.stringify({
        'grant_type': 'client_credentials',
        'client_id': client_id,
        'client_secret': client_secret
    });
    https.get(
        {
            hostname: 'aip.baidubce.com',
            path: '/oauth/2.0/token?' + param,
            agent: false
        },
        function (res) {
            res.pipe(fs.createWriteStream('./'+ type +'-token.json'))
        }
    );
} 